package com.ruoyi.use.aspect;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.use.domain.ExaminationUse;
import com.ruoyi.use.service.IExaminationUseService;
import com.ruoyi.examination.domain.Examination;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class ExamInsertAspect {

    @Autowired
    IExaminationUseService examinationUseService;

    @Pointcut("execution(public * com.ruoyi.examination.service.IExaminationService.insert*(..))")
    public void myMethod(){
        //代理方法
    }
    @After("myMethod()")
    public void afterMethod(JoinPoint joinPoint){
        Object[] args = joinPoint.getArgs();
        for (Object every : args) {
            ExaminationUse examinationUse = new ExaminationUse();
            if (every instanceof Examination){
                Examination eve=(Examination) every;
                examinationUse.setExaminationId(eve.getExaminationId());
                SysUser sysUser = ShiroUtils.getSysUser();
                examinationUse.setFounder(sysUser.getUserId());
                examinationUse.setOperationName(0L);
                examinationUseService.insertExaminationUse(examinationUse);
            }
        }
    }
}
